﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace OL.FrameCore.Infrastructure.Utility
{
    public class StringHandle
    {
        public static string GetSummaryString(string content, int length)
        {
            content = System.Text.RegularExpressions.Regex.Replace(content, "<[^>]*>|&nbsp;", "");
            if (content.Length > length)
            {
                content = content.Substring(0, length);
            }

            return content;
        }

        public static string GetFirstImagePaht(string content)
        {
            Regex regex = new Regex(@"<img[^>]+src=\s*(?:'(?<src>[^']+)'|""(?<src>[^""]+)""|(?<src>[^>\s]+))\s*[^>]*/>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
            var match = regex.Match(content);
            if (match.Success)
            {
                return match.Groups["src"].Value;
            }
            return "";
        }
    }
}
